class ApplicationController < ActionController::Base
  protect_from_forgery
  
  respond_to :html
  
  helper_method :current_person, :person_signed_in?
  
  after_filter :set_access_control_headers
  
  protected
        
    def person_signed_in?
      !!current_person
    end
    
    def current_person=(new_person)
      session[:person_id] = new_person ? new_person.id : nil
      @current_person = new_person || false
    end
    
    def current_person
       @current_person ||= person_login_from_session unless @current_person == false
    end
    
    def person_login_from_session
      self.current_person = Person.find_by_id(session[:person_id]) if session[:person_id]
    end
    
    def set_access_control_headers
      headers['Access-Control-Allow-Origin'] = '*'
      headers['Access-Control-Request-Method'] = '*'
      headers["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"' if request.user_agent.include?('MSIE')
    end
end
